let plugs = {
    formatTime:function(time,fmt){
        if (time == null) {
            return;
        }
        var fmt = fmt ? fmt : 'yyyy-MM-dd hh:mm:ss';
        var time = new Date(time);
        var z = {
                M: time.getMonth() + 1,
                d: time.getDate(),
                h: time.getHours(),
                m: time.getMinutes(),
                s: time.getSeconds()
            };
        var index = 0;
        fmt = fmt.replace(/(M+|d+|h+|m+|s+)/g, function(v) {
           return ((v.length > 1 ? '0' : '') + z[v.slice(-1)]).slice(-2);
        });
        return fmt.replace(/(y+)/g, function(v) {
            return time.getFullYear().toString().slice(-v.length);
        });
    },
    objExtend:function(obj1,obj2){
        for(var k in obj2){
            obj1[k] = obj2[k];
        }
        return obj1;
    },
    ajax:function({url,data,success,method = 'GET'}){
            let host = 'https://gzdx.natapp4.cc/index.php?s=',
            header = {
                'content-type':'application/json'
            },
            fail = function(err) {
                wx.hideLoading();
                wx.showToast({
                    title:err.info || '请求失败',
                    icon:'none'
                })
            };
        wx.showLoading();
        wx.request({
            url:host+url,
            method:method,
            header:header,
            data:data,
            success:(res) => {
                wx.hideLoading();
                if (res.statusCode == 200) {
                    if (res.data.state === 0) {
                        fail(res.data);
                        return;
                    }
                    success(res.data)  
                }else{
                    fail(res.data);
                }
            }
        })
    }
}


module.exports = plugs;